<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.DriverManager" %><%--
  Created by IntelliJ IDEA.
  User: Mr.Zhang
  Date: 2018/3/20
  Time: 16:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>userList</title>
    <style type="text/css">
        table{border: 1px solid #000000;
            border-collapse: collapse;
            align:center;
            margin: auto;
            vertical-align: middle;
        }
        td,th{border: 1px solid #000000;
            padding: 8px;

        }
        h2,p{text-align:center}


    </style>
</head>
<body>
    <h2>用户信息管理系统</h2>

    <%
        //判断用户是否登录
       if (session.getAttribute("isLogin")==null){

           //没有登录，跳转到login.jsp
           response.sendRedirect("login.jsp");
       }
    %>
    <table>
        <thead>
        <tr>
            <th>编号</th>
            <th>用户名</th>
            <th>密码</th>
            <th>管理</th>
        </tr>
        </thead>
        <tbody>

            <%
                /*class User{
                    int id;
                    String name;
                    String password;

                    public User(int id, String name, String password) {
                        this.id = id;
                        this.name = name;
                        this.password = password;
                    }
                }*/
                //List<User> list=new ArrayList<User>();

                Connection connection=null;
                Statement statement=null;
                ResultSet resultSet=null;

                String sql="select * from t_users";

                Class.forName("com.mysql.jdbc.Driver");

                connection= DriverManager.getConnection(
                        "jdbc:mysql://localhost:3306/sctu_javaweb_2018?useUnicode=true&characterEncoding=GBK",
                        "root",
                        "123456"
                        );
                statement=connection.createStatement();

                resultSet=statement.executeQuery(sql);

                while (resultSet.next()){
                    int id=resultSet.getInt(1);
            %>
            <tr>
                <td><%=resultSet.getInt("id")%></td>
                <td><%=resultSet.getString("userName")%></td>
                <td><%=resultSet.getString("password")%></td>
                <td><a href="userEdit.jsp?id=<%=id%>">更新</a>&nbsp;&nbsp;
                    <a href="userDelete.jsp?id=<%=id%>">删除</a></td>
            </tr>


<%--//                    User user=new User(id,username,password);--%>
<%--//                    list.add(user);--%>

               <%
                   }
                resultSet.close();
                statement.close();
                connection.close();
                %>
        </tbody>
    </table>
    <p><a href="userAdd.html">添加用户</a></p>

    <a href="logout.jsp">退出</a>
</body>
<%--<%@include file="footer.jsp" %>--%>

<jsp:include page="footer.jsp"></jsp:include>
</html>
